home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Atari Compendium
/
The Atari Compendium (Toad Computers) (1994).iso
/
files
/
compress
/
unix
/
unz50p1.zoo
/
zipinfo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-01-10
|
59KB
|
1,556 lines
/*---------------------------------------------------------------------------
zipinfo.c
This program reads all sorts of totally nifty information, including the
central directory stuff, from a ZIP archive ("zipfile" for short). It
started as just a testbed for fooling with zipfiles, but at this point
it's actually a moderately useful utility. It also became the basis
for the rewrite of unzip (3.16 -> 4.0), using the central directory for
processing rather than the individual (local) file headers.
For myself, I find it convenient to define an alias "ii" (under Unix and
VMS) or to rename the executable to "ii.exe" (OS/2 and DOS). This nicely
complements my Unix long-listing "ll" alias (ls -lF), since zipinfo's de-
fault action is to produce a Unix-like listing of the archive's contents.
"ii zipfile" is easier to type than "zipinfo zipfile"...
Another dandy product from your buddies at Newtware!
---------------------------------------------------------------------------
To compile (partial instructions; some of this stuff doesn't exist yet):
under Unix (cc): make zipinfo
under MS-DOS (TurboC): make -fMKZIPINF.DOS (edit appropriately)
under MS-DOS (MSC): make MKZIPINF.DOS
(or use Makefile if you have MSC 6.0: "nmake zi_dos")
under OS/2 (MSC): make MKZIPINF.DOS (edit appropriately)
(or use Makefile if you have MSC 6.0: "nmake zi_os2")
under Atari OS: beats me...
under VMS: @MAKE_ZIPINFO (see also VMSNOTES)
ZIPINFO == $DISKNAME:[DIRECTORY]ZIPINFO.EXE
under Macintosh OS: who knows?
---------------------------------------------------------------------------
Source: unz50p1.zip (.tar.Z, etc.) for Unix, VMS, OS/2 and MS-DOS; see
`Where' in source distribution for ftp, uucp and mail-server
sites.
Author: Greg Roelofs, roelofs@nas.nasa.gov, 23 August 1990
Copyright: Portions copyright 1992 Greg Roelofs. Portions adapted from
unzip 3.1. SizeOfEAs() by Kai Uwe Rommel.
---------------------------------------------------------------------------*/
#ifndef ZIPINFO
# define ZIPINFO /* needed for Unix permissions in non-Unix environments */
#endif /* !ZIPINFO */
#include "unzip.h"
#define VERSION "v1.0p1 of 10 January 1993"
#define LFLAG 3 /* for short "ls -l" type listing */
#define EAID 0x0009 /* OS/2 EA extra field ID */
typedef struct { /* for OS/2 info in OS/2 and non-OS/2 environments */
unsigned short nID;
unsigned short nSize;
ULONG lSize;
} EAHEADER, *PEAHEADER;
/**********************/
/* Global Variables */
/**********************/
#ifdef EBCDIC
int aflag=1; /* this is so you can read it on the screen */
#else /* (basically, entire program is "unzip -c") */
int aflag=0;
#endif
int lflag=(-1); /* '-1slmv': listing format */
int hflag=0; /* '-h': header line */
int tflag=0; /* '-t': totals line */
byte *inbuf, *inptr; /* input buffer (any size is legal) and pointer */
int incnt;
int zipfd; /* zipfile file handle */
char zipfn[FILNAMSIZ];
char local_hdr_sig[5] = "\120"; /* remaining signature bytes come later: */
char central_hdr_sig[5] = "\120"; /* must initialize at runtime so zipinfo */
char end_central_sig[5] = "\120"; /* executable won't look like a zipfile */
char extd_local_sig[5] = "\120";
cdir_file_hdr crec; /* used in zipinfo.c, misc.c */
local_file_hdr lrec;
ecdir_rec ecrec;
struct stat statbuf; /* used by main() */
int process_all_files;
longint real_ecrec_offset, expect_ecrec_offset;
longint extra_bytes=0; /* used in zipinfo.c, misc.c */
longint cur_zipfile_bufstart; /* find_end_central_dir, readbuf */
min_info info, *pInfo=(&info);
byte *extra_field = NULL; /* used by VMS, Mac and OS/2 versions */
byte *outbuf; /* buffer for rle look-back, zipfile comment */
byte *outout; /* scratch pad for ASCII-native trans */
char filename[FILNAMSIZ];
char sig[5];
char *fnames[2] = {"*", NULL}; /* default filenames vector */
char **fnv = fnames;
static byte *hold;
static longint ziplen;
static UWORD hostnum;
static UWORD methnum;
static UWORD extnum;
char *EndSigMsg = "\nwarning:\
didn't find end-of-central-dir signature at end of central dir.\n";
char *CentSigMsg =
"error: expected central file header signature not found (file #%u).\n";
char *SeekMsg =
"error: attempt to seek before beginning of zipfile\n%s";
#ifdef VMS
char *ReportMsg = "\
(please check that you have transferred or created the zipfile in the\n\
appropriate BINARY mode--this includes ftp, Kermit, AND unzip'd zipfiles)\n";
#else /* !VMS */
char *ReportMsg = "\
(please check that you have transferred or created the zipfile in the\n\
appropriate BINARY mode and that you have compiled unzip properly)\n";
#endif /* ?VMS */
/******************/
/* Main program */
/******************/
main(argc, argv)
int argc;
char *argv[];
{
char *s;
int c, error=FALSE, negative=0;
int hflag_slmv=TRUE, hflag_1=FALSE; /* diff options => diff defaults */
int tflag_slm=TRUE, tflag_1v=FALSE;
int explicit_h=FALSE, explicit_t=FALSE;
/*---------------------------------------------------------------------------
Everybody is now "NOTINT16," but this is a nice little piece of code, so
just comment it out for future reference. :-)
---------------------------------------------------------------------------*/
#if 0
# ifndef KNOW_IT_WORKS /* define this to save space, if things already work */
# ifndef DOS_OS2 /* already works (no RISCy OS/2's yet...) */
# ifndef NOTINT16 /* whole point is to see if this NEEDS defining */
{
int error=0;
long testsig;
static char *mach_type[3] = {"big-endian", "structure-padding",
"big-endian and structure-padding"};
strcpy((char *)&testsig,"012");
if (testsig != 0x00323130)
error = 1;
if (sizeof(cdir_file_hdr) != CREC_SIZE)
error += 2;
if (error--)
fprintf(stderr, "It appears that your machine is %s. If errors\n\
occur, please try recompiling with \"NOTINT16\" defined (read the\n\
Makefile, or try \"make zipinfo\").\n\n", mach_type[error]);
}
# endif /* !NOTINT16 */
# endif /* !DOS_OS2 */
# endif /* !KNOW_IT_WORKS */
#endif /* 0 */
/*---------------------------------------------------------------------------
Put environment-variable options into the queue, then rip through any
command-line options lurking about...
---------------------------------------------------------------------------*/
envargs(&argc, &argv, ENV_ZIPINFO);
while (--argc > 0 && (*++argv)[0] == '-') {
s = argv[0] + 1;
while ((c = *s++) != 0) { /* "!= 0": prevent Turbo C warning */
switch (c) {
case '-':
++negative;
break;
case '1': /* shortest listing: just filenames */
if (negative)
lflag = -2, negative = 0;
else
lflag = 1;
break;
case 'h': /* header line */
if (negative)
hflag_1 = hflag_slmv = FALSE, negative = 0;
else {
hflag_1 = hflag_slmv = explicit_h = TRUE;
if (lflag == -1)
lflag = 0;
}
break;
case 'l': /* longer form of "ls -l" type listing */
if (negative)
lflag = -2, negative = 0;
else
lflag = 5;
break;
case 'm': /* medium form of "ls -l" type listing */
if (negative)
lflag = -2, negative = 0;
else